﻿using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
using System;

#region     
string PythonScriptPath = string.Empty;
var basepath = AppDomain.CurrentDomain.BaseDirectory;
ScriptEngine PyEngine = Python.CreateEngine();


PythonScriptPath = basepath+ "/py/setup.py";

dynamic py = PyEngine.ExecuteFile(PythonScriptPath);
//var sum = py.func('3', '5');
Console.WriteLine("求和：");
Console.WriteLine("请输入第一个数字");
decimal one = Convert.ToDecimal(Console.ReadLine());
Console.WriteLine("请输入第二个数字");
decimal two = Convert.ToDecimal(Console.ReadLine());

var sum = py.func(one, two);
Console.WriteLine("add 方法的和是：{0}", sum);
Console.ReadKey();
#endregion


#region pythonnet

//string pathToVirtualEnv = @"C:\software\python\install";
//Runtime.PythonDLL = pathToVirtualEnv + "\\python313.dll";
//string pythonHome = pathToVirtualEnv + "\\python.exe";
//PythonEngine.PythonHome = pythonHome;

//PythonEngine.PythonPath = $"{pathToVirtualEnv}\\Lib\\site-packages;{pathToVirtualEnv}\\Lib;C:\\code\abp\\dotnetpython\\dotnetpythonDemo\\py\\";

//PythonEngine.Initialize();
//using (Py.GIL())
//{   // TestDemo为TestDemo.py文件，在放在D:\\tempCode\\ 目录
//    dynamic np = Py.Import("setup");
//    double r = np.func(9, 27);
//    Console.WriteLine($"计算结果{r}");//计算结果为6
//}
////也可以直接搞用第三方库numpy里面的方法
//using (Py.GIL())
//{
//    dynamic np = Py.Import("numpy");
//    double r = np.sqrt(64);
//    Console.WriteLine($"计算结果{r}");//计算结果为8
//}

#endregion